<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>服务器在用情况统计</title>
    <link rel="stylesheet" href="{{ url_for('static',filename='CSS/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='CSS/admin.css') }}">
    <script src="{{ url_for('static',filename='JS/jquery-3.5.1.js') }}"></script>
    <script src="{{ url_for('static',filename='JS/bootstrap.min.js') }}"></script>
    <script src="{{ url_for('static',filename='JS/admin.js') }}"></script>
</head>
<body>

<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand">服务器在用情况统计(SUS)</a>
        </div>
        <div class="logout">
            <button type="button" class="btn btn-default btn-sm" id="logout" name="logout">
                <span class="glyphicon glyphicon-log-out"></span>退出
            </button>
        </div>
    </div>
</nav>

<div class="dev_list">
    <table class="table table-bordered">
        <thead>
        <div class="add_device">
            <input class="btn btn-default" type="submit" id="add_device" name="add_device" value="添加">
        </div>
        <tr>
            <td class="number"><strong>No.</strong></td>
            <td class="serialnumber"><strong>序列号</strong></td>
            <td class="model"><strong>型号</strong></td>
            <td class="cpu_model"><strong>CPU型号</strong></td>
            <td class="cpu_cores"><strong>CPU核数</strong></td>
            <td class="bmc_address"><strong>BMC地址</strong></td>
            <td class="purpose"><strong>用途</strong></td>
            <td class="owner"><strong>使用者</strong></td>
            <td class="others"><strong>备注</strong></td>
            <td class="operation"><strong>操作</strong></td>
        </tr>
        </thead>
        <tbody>
        {% for device in data %}
            <tr sid="{{ device.sid }}">
                <td>{{ loop.index }}</td>
                <td>{{ device.sid }}</td>
                <td>{{ device.model }}</td>
                <td>{{ device.cpu_model }}</td>
                <td>{{ device.cpu_cores }}</td>
                <td>{{ device.bmc_address }}</td>
                <td>{{ device.purpose }}</td>
                <td>{{ device.owner }}</td>
                <td>{{ device.others }}</td>
                <td>
                    <input type="button" name="edit_device" class="edit_device btn btn-primary" value="编辑">
                    <input type="button" name="del_device" class="btn btn-danger" data-toggle="modal"
                           data-target="#delModal" value="删除" onclick="showDeleteModal(this)">
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>

<!-- Modal -->
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="delModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="delModalLabel">删除设备</h4>
            </div>

            <div class="modal-body">
                <input type="hidden" id="confirm_del_dev">
                确定删除该设备吗？
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary confirm_delete">确定</button>
            </div>

        </div>
    </div>
</div>


<div class="alert alert-warning">
    <p>作者说：</p>
    <p>可以提出需求，提了我也不做。你可以提建议，但不一定会采纳 <span class="glyphicon glyphicon-comment"></span></p>
    <p>接受狗狗币打赏，不给就算了，反正你也习惯了白嫖！狗狗币地址：DGRN9SB9AWVKj14LodHV3Txwu6CMD6dCcJ</p>
    <p>需要源码请移步码云:
        <a href="https://gitee.com/china_chenyang/cmdb.git" target="_blank">
            <span class="glyphicon glyphicon-floppy-save"></span>
        </a>
    </p>
</div>

</body>
</html>

<script>
    function showDeleteModal(obj) {
        /* 打开删除确认对话框的同时执行该函数，获取tr元素中的sid值，
           将获取的sid值作为id为confirm_del_dev的value
        */
        var tr_element = $(obj).parent().parent();
        var serialnumber = tr_element.attr("sid");
        $("#confirm_del_dev").val(serialnumber);
    }
</script>